﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>流程事件类</title>
    <meta charset="UTF-8" />
    <title>节点-事件</title>
    <!--SQL编辑器-->
    <link href="../../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" />
    <link href="../../Scripts/CodeMirror/lib/codemirror.css" rel="stylesheet" />
    <link href="../../Scripts/CodeMirror/addon/hint/show-hint.css" rel="stylesheet" />
    <script src="../../Scripts/CodeMirror/lib/codemirror.js"></script>
    <script src="../../Scripts/CodeMirror/addon/edit/matchbrackets.js"></script>
    <script src="../../Scripts/CodeMirror/mode/sql/sql.js"></script>
    <script src="../../Scripts/CodeMirror/addon/hint/show-hint.js"></script>
    <script src="../../Scripts/CodeMirror/addon/hint/sql-hint.js"></script>
    <script src="../../Scripts/LoadSql.js"></script>
    <script src="../../Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>

    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>


    <link href="../../Style/skin/css/Default.css" rel="stylesheet" />
    <link href="../../Style/skin/adminfont/iconfont.css" rel="stylesheet" />
    <link href="../../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../Comm/Gener.js"></script>
    <script src="../Admin.js"></script>

    <script type="text/javascript">
        //页面启动函数.
        $(function () {

            $("#Msg").html("正在加载,请稍后......");

            //初始化groupID.
            var flowNo = GetQueryString("FK_Flow");

            //绑定事件类型.
            GenerBindEnumKey("DDL_EventDoType", "EventDoType", "0");
            $("#DDL_EventDoType").trigger("change");

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_AttrNode");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("ActionDtl_Init");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            // 业务单元
            var BuessUnits = JSON.parse(data);
            GenerBindDDL("DDL_Doc", BuessUnits, "No", "Name", "");

        });

        function GetDoType(doType) {

            var cfg = "@0=禁用@1=执行存储过程@2=执行SQL语句@3=执行URL@4=WebServices(未完成)@5=执行ddl文件的类与方法@6=EventBase类@7=业务单元";

            var cfgs = cfg.split('@');

            for (var i = 0; i < cfgs.length; i++) {
                var vss = cfgs[i];
                if (vss.indexOf('=') == -1)
                    continue;

                var vals = vss.split('=');

                if (vals[0] == doType)
                    return vals[1];
            }

            return doType + 'ss';
        }

        function Save() {

            var en = new Entity("BP.Sys.FrmEvent");
            en.CopyForm();
            en.FK_Flow = GetQueryString("FK_Flow");
            en.EventSource = 1;//流程事件

            //如果是业务单元.
            if (en.EventDoType == 7) {
                en.DoDoc = $("#DDL_Doc").val();
            } else {
                en.DoDoc = editor.getValue();
            }

            if (en.DoDoc == "") {
                alert('设置执行内容.');
                return;
            }

            en.SetPKVal(en.FK_Event + Math.random());
            en.Insert();


            Back();


            return;
        }

        function doChangeContent(o) {
            if ($(o).val() == "7")
                $("#DDL_Doc").show();
            else
                $("#DDL_Doc").hide();


            if ($(o).val() == "8")
                $("#sp_webapi").show();
            else
                $("#sp_webapi").hide();
        }

        function Back() {
            var url = "Action.htm?FK_Flow=" + GetQueryString("FK_Flow");
            SetHref(url);
        }
    </script>
</head>
<body>
    <div class="container-full">

        <div id="titleH4" class="attrnode-bar-header">
            <span class="pull-right">
                <button id="Btn_Save" class="cc-btn-tab btn-save" onclick="Save();">保存</button>
                <button id="Btn_Back" class="cc-btn-tab btn-back" onclick="Back();">返回</button>
            </span>
            <strong>新增事件 </strong>
        </div>
        <form id="cc">

            <div style="position:relative;">
                <table class="table" id="Table2">
                    <tr>
                        <td>事件类型</td>
                        <td>
                            <select id="DDL_FK_Event" name="DDL_FK_Event">
                                <option value="FlowOnCreateWorkID">  创建工作ID后 </option>
                                <option value="FlowOverBefore" selected="selected">  流程结束前</option>
                                <option value="FlowOverAfter">  流程结束后</option>
                                <option value="BeforeFlowDel">  流程删除前</option>
                                <option value="AfterFlowDel">  流程删除后</option>
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td>执行内容类型</td>
                        <td><select id="DDL_EventDoType" name="DDL_EventDoType" onchange="doChangeContent(this)"></select></td>
                    </tr>

                    <tr>
                        <td>执行内容</td>
                        <td>

                            <textarea id="TB_SQL" name="TB_Doc" style="display: none; width:98%;"></textarea>	<!-- 其它事件 -->
                            <select id="DDL_Doc" name="DDL_Doc" style="display: none;"></select>	<!-- 业务单元 -->
                            <span id="sp_webapi" style="color:blue">调用事件时，无论成功与否，都不会影响流程正常运行，如果需要阻断流程执行，请自定义方法，比如抛出异常</span>
                        </td>
                    </tr>

                    <tr>
                        <td colspan=1>
                            执行成功信息提示(可为空)
                        </td>
                        <td colspan=1>
                            <input type=text id="MsgOK" name="MsgOK" />
                        </td>
                    </tr>

                    <tr>
                        <td colspan=1>
                            执行失败时提示(可为空)
                        </td>

                        <td>
                            <input type=text id="MsgError" name="MsgError" />
                        </td>
                    </tr>
                </table>

                <fieldset>
                    <legend>帮助</legend>
                    <ul>
                        <li>1. 支持ccbpm表达式,什么是bpm表达式,请参考. </li>
                        <li>2. 支持 @PTable 表达式, 比如: UPDATE @PTable SET MyFile1='xxx' WHERE OID=@WorkID </li>
                    </ul>


                    <legend>关于:存储过程</legend>
                    <ul>
                        <li>
                            create procedure dbo.sp_throwErr
                            @para VARCHAR
                            as
                            begin
                            declare  @raiseErrorCode nvarchar(50)
                            if (@para is not null)
                            RAISERROR(N'%s err@错误没有收到款,不能发货.',16,1, @raiseErrorCode,5)
                            end
                        </li>
                        <li>如果返回值是:err@ 就说明是异常，系统就终止运行.</li>
                    </ul>


                    <legend>关于:SQL</legend>
                    <ul>
                        <li>可以写多条SQL</li>
                        <li>
                            DELETE FROM XXX WHERE OID=@WorkID;
                            UPDATE FROM XXX SET ABC='XXX' WHERE  OID=@WorkID;
                        </li>
                        <li>系统不解析返回值，如果执行异常，就停止(卡住)，ccbpm不处理数据回滚。</li>
                    </ul>

                </fieldset>
            </div>


        </form>

    </div>

</body>
</html>
